{include file="public/header" /}

<div class="page">
    <form id="user_form" enctype="multipart/form-data" method="post" >

        <table class="sc-default-table">
            <tbody>

            <input type="hidden" name="member_id" value="{$member_id}">
            <input type="hidden" name="rc_id" id="rc_id">

            <tr class="noborder">
                <td class="required w120"><label>会员卡卡号:</label></td>
                <td class="vatop rowform">
                    <input type="text" id="input_number" class="txt">
                </td>
                <td class="vatop tips"></td>
            </tr>

            </tbody>

            <tfoot>
            <tr class="tfoot">
                <td colspan="15"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span>{$Think.lang.sc_save}</span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>

    <script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script>
    <script type="text/javascript">
        $(function () {

            $("#submitBtn").click(function () {
                if ($("#user_form").valid()) {
                    // 异步查询 value=$("#input_number").val() 对应的卡id，更新到 $("#rc_number").val(value)

                    let url = '{:url("get_rcid_by_rcsn")}'
                    let param = {rc_number: $("#input_number").val()}
                    $.get(url, param, function (result) {
                        if (result.code == 0) {
                            return layer.msg(result.msg, {time: 1000});
                        }
                        $("#rc_id").val(result.data.rc_id)
                        // $("#user_form").submit();
                        sc_ajaxpost('user_form', 'parent_reload')
                    })
                }
            });

            $('#user_form').validate({
                errorPlacement: function (error, element) {
                    error.appendTo(element.parent().parent().find('td:last'));
                },
                rules: {
                    reciver_name: {
                        required: true,
                    },
                    reciver_mobile: {
                        required: true,
                    },
                    region: {
                        checklast: true
                    },
                    reciver_street: {
                        required: true
                    },
                },
                messages: {
                    reciver_name: {
                        required: '收货人必填'
                    },
                    reciver_mobile: {
                        required: '收货人手机号必填',
                    },
                    region: {
                        checklast: '区域不完整'
                    },
                    reciver_street: {
                        required: '街道必填'
                    },
                }
            });
        });
    </script>
</div>
